package alloy.transform.atomize;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

import alloy.ast.FindCommand;

/**
 * State used across an an entire compilation / execution.
 * 
 * @author drayside
 * 
 */

public class AtomizationState {

	/** stores all Signatures (not Signature's) in all modules */
	final Set _allSigs = new LinkedHashSet();

	/**
	 * A stringToType map that only contains new SigTypes created during
	 * atomization (i.e. remainder types).
	 */
	final Map _createdStringToType = new LinkedHashMap();

	/**
	 * Map commands to their AtomizationInfo
	 */
	final Map _commandToAtomizationInfo = new HashMap();

	/**
	 * Commands that have been atomized.
	 */
	final Set _atomizedCommands = new LinkedHashSet();
	
	/**
	 * To prevent instantiation.  This is just a holder for global state.
	 */
	private AtomizationState() {}
	
	CommandState getAtomizationInfo(final FindCommand cmd) {
		if (_commandToAtomizationInfo.containsKey(cmd)) {
			return (CommandState) _commandToAtomizationInfo.get(cmd);
		} else {
			final CommandState info = new CommandState(cmd);
			_commandToAtomizationInfo.put(cmd, info);
			return info;
		}

	}

	public static CommandState.FixLeafIdsVisitor getFLIV(
			final FindCommand cmd) {
		return ((CommandState) state._commandToAtomizationInfo
				.get(cmd))._fliv;
	}

	public static Map getAtomizedIdToOldLeafExpr(final FindCommand cmd) {
		return ((CommandState) state._commandToAtomizationInfo
				.get(cmd))._atomizedIdToOldLeafExpr;
	}

	static AtomizationState state = null;

	public static void init() {
		state = new AtomizationState();
	}

}
